package com.itheima.Demo;

import java.util.concurrent.atomic.AtomicInteger;

//卖票案例;
public class AAA implements Runnable {
    //一共有100张票
    //int a = 100;
    //解决办法;
    AtomicInteger a = new AtomicInteger(100);

    @Override
    public void run() {
        while (true) {
            //通过对象名来调用;
            if (a.get() <= 0) {
                break;
            }
            System.out.println(Thread.currentThread().getName() + "卖出了" + a + "号票");
            // a--;
            a.getAndDecrement();
        }
    }
}


